﻿using System;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.GFMS.MODEL;
using KPIS.GERP.GFMS.IDAL;

namespace KPIS.GERP.GFMS.DAL
{
    public class D_HRM_MAS_Countries : IDAL_HRM_MAS_Countries
    {
        DBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);
        ConvertNullable cn = new ConvertNullable();
        

        public D_HRM_MAS_Countries()
        {

        }

        public IList<M_HRM_MAS_Countries> GetFull()
        {
            string strSQL;
            DataRowCollection drc = null;
            IList<M_HRM_MAS_Countries> infoList = new List<M_HRM_MAS_Countries>();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);

                dbManager.AddParameters(0, "@delete_status", SystemInfo._DeleteRecordStatus);

                strSQL = "SELECT country_seq, country_name, country_name_eng, local, record_status"
                    + " FROM mas_countries"
                    + " WHERE record_status not like @delete_status"
                    + " ORDER BY country_name";
                

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    for (int i = 0; i < drc.Count; i++)
                    {
                        M_HRM_MAS_Countries info = new M_HRM_MAS_Countries();
                        info.country_seq = Convert.ToInt32(drc[i]["country_seq"]);
                        info.country_name = drc[i]["country_name"].ToString();
                        info.country_name_eng = drc[i]["country_name_eng"].ToString();
                        info.local = drc[i]["local"].ToString();
                        info.record_status = drc[i]["record_status"].ToString();
                        infoList.Add(info);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return infoList;
        }

        public IList<M_HRM_MAS_Countries> GetList()
        {
            string strSQL;
            DataRowCollection drc = null;
            IList<M_HRM_MAS_Countries> infoList = new List<M_HRM_MAS_Countries>();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);

                dbManager.AddParameters(0, "@delete_status", SystemInfo._DeleteRecordStatus);

                strSQL = "SELECT country_seq, country_name"
                    + " FROM mas_countries"
                    + " WHERE record_status not like @delete_status"
                    + " ORDER BY country_name";
                

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    for (int i = 0; i < drc.Count; i++)
                    {
                        M_HRM_MAS_Countries info = new M_HRM_MAS_Countries();
                        info.country_seq = Convert.ToInt32(drc[i]["country_seq"]);
                        info.country_name = drc[i]["country_name"].ToString();
                        infoList.Add(info);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return infoList;
        }

        public M_HRM_MAS_Countries GetInfo(int seq)
        {
            string strSQL;
            DataRowCollection drc = null;
            M_HRM_MAS_Countries info = new M_HRM_MAS_Countries();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);

                dbManager.AddParameters(0, "@seq", seq);

                strSQL = "SELECT country_seq, country_name, country_name_eng, local, record_status"
                    + " FROM mas_countries"
                    + " WHERE record_status not like @delete_status";
                

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    info.country_seq = Convert.ToInt32(drc[0]["country_seq"]);
                    info.country_name = drc[0]["country_name"].ToString();
                    info.country_name_eng = drc[0]["country_name_eng"].ToString();
                    info.local = drc[0]["local"].ToString();
                    info.record_status = drc[0]["record_status"].ToString();
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return info;
        }

        //DBManager dbManager = new DBManager(SystemInfo._DataProvider, ConfigurationSettings.AppSettings["ConnectionString"].ToString());
        //

        //public DataTable SelectGrid()
        //{
        //    string strSQL;
        //    DataTable dtb = null;

        //    try
        //    {
        //        dbManager.Open();

        //        strSQL = "SELECT country_seq, country_name, country_name_eng, local, record_status"
        //            + " FROM mas_countries"
        //            + " WHERE record_status not like 'D'";
        //        

        //        dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
        //    }
        //    catch
        //    {
        //        throw;
        //    }
        //    finally
        //    {
        //        dbManager.Dispose();
        //    }

        //    return dtb;
        //}

        //public DataTable SelectDropDownList()
        //{
        //    string strSQL;
        //    DataTable dtb = null;

        //    try
        //    {
        //        dbManager.Open();

        //        strSQL = "SELECT null as country_seq, null as country_name"
        //            + " UNION ALL"
        //            + " SELECT country_seq, country_name"
        //            + " FROM mas_countries"
        //            + " WHERE record_status not like 'D'";
        //        

        //        dtb = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
        //    }
        //    catch
        //    {
        //        throw;
        //    }
        //    finally
        //    {
        //        dbManager.Dispose();
        //    }

        //    return dtb;
        //}
    }
}
